/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package org.letmeshare.stockkeeper.view.dashboard;


import java.awt.Component;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Label;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.KeyEvent;
import java.awt.font.GraphicAttribute;
import java.util.HashMap;
import java.util.Map;
import javax.swing.ImageIcon;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.event.MenuEvent;
import javax.swing.event.MenuListener;
import org.letmeshare.stockkeeper.AppInit;
import org.letmeshare.stockkeeper.PersistenceManager;

/**
 *
 * @author abin
 */
public class Dashboard extends JFrame {

    private Component component;JLabel imageJLabel;

    public Dashboard() throws Exception{
        JMenuBar bar=new JMenuBar();
        JMenu purchase=new JMenu("Purchase");
        purchase.addMenuListener(new MenuListenerImp()); purchase.setMnemonic(KeyEvent.VK_F1);
        bar.add(purchase);
       
        
        JMenu sale=new JMenu("Sale");
        sale.addMenuListener(new MenuListenerImp()); sale.setMnemonic(KeyEvent.VK_F2);
        bar.add(sale);
        
        JMenu store_room=new JMenu("Store Room");
        store_room.addMenuListener(new MenuListenerImp());store_room.setMnemonic(KeyEvent.VK_F3);
        bar.add(store_room);
        
        JMenu report=new JMenu("Report");
        report.addMenuListener(new MenuListenerImp());report.setMnemonic(KeyEvent.VK_F4);
        bar.add(report);
        
        JMenu exit=new JMenu("Exit");
        exit.addMenuListener(new MenuListenerImp());
        //bar.add(exit);
        
      
        setJMenuBar(bar);
        setSize(AppInit.GetScreenWorkingWidth(), AppInit.GetScreenWorkingHeight());
        setTitle("Store Keeper -Dashboard");
        setVisible(true);
        setMinimumSize(new Dimension(AppInit.GetScreenWorkingWidth(), AppInit.GetScreenWorkingHeight()));
        setIconImage(AppInit.getIcon());
       
        setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       component=new JPanel();
        add(component);
        onMenuClick(new Home());
    }
    private void onMenuClick(Component c){
        if(component!=null){remove(component);}
        
        component=c;
        add(c);
        pack();
        repaint();
    }
    private class MenuListenerImp implements MenuListener{

        public void menuSelected(MenuEvent e) {
            PersistenceManager.rollback();
            if(((JMenu)e.getSource()).getText().equalsIgnoreCase("Purchase")){
                 setTitle("Purcase   - Store Keeper");
                onMenuClick(new PurchasePanel());
            }else if(((JMenu)e.getSource()).getText().equalsIgnoreCase("sale")){
                setTitle("Sale  - Store Keeper");
                onMenuClick(new BillPanel());
                
            }else if(((JMenu)e.getSource()).getText().equalsIgnoreCase("Store Room")){
                setTitle("Store room  - Store Keeper");
                onMenuClick(new StoreRoom());
                
            }else if(((JMenu)e.getSource()).getText().equalsIgnoreCase("Report")){
                setTitle("Report   - Store Keeper");
               onMenuClick(new Report());
                
            }else if(((JMenu)e.getSource()).getText().equalsIgnoreCase("exit")){
                
                
            }
        }

        public void menuDeselected(MenuEvent e) {
           
        }

        public void menuCanceled(MenuEvent e) {
           
        }
        
    }
}
